<template>
  <view>
    <block v-for="(item,index) in goodsList" :key="index">
      <MyGoodsItem :goods="item" @click.native="goToDetail(item)"></MyGoodsItem>
    </block>
  </view>
</template>

<script>
  export default {
    data() {
      return {
 
        queryObj:{
          cid:'',
          query:'',
          pagenum:1,
          pagesize:10
        },
        goodsList:[],
        total:0
      };
     
    },

    onLoad(options){
      this.total=1
      this.queryObj.query=options.query||""
      this.queryObj.cid=options.cid||""
      this.getGoodsList()
    },
    onPullDownRefresh(){
      this.goodsList=[]
      this.queryObj.pagenum=1
      this.getGoodsList()
    },
    onReachBottom(){
     if(this.total<=this.goodsList.length){
       return uni.$showMsg("数据加载完毕！")
     }
      this.queryObj.pagenum+=1
      this.getGoodsList()
    },
    methods:{
      async getGoodsList(){
        let {data:res}=await uni.$http.get('/api/public/v1/goods/search',this.queryObj)
        if(res.meta.status!==200) uni.$showMsg("获取商品列表失败！")
        this.goodsList.push(...res.message.goods)
        this.total=res.message.total
        uni.stopPullDownRefresh()
      },
      goToDetail(item){
        uni.navigateTo({
          url:"/subpkg/goods_detail/goods_detail?goods_id="+item.goods_id
        })
      }
    }
  }
</script>

<style lang="scss">

</style>
